package constant.milk.cashbook.sms.parser;

import java.util.Calendar;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import constant.milk.cashbook.bean.SmsInputData;
import constant.milk.cashbook.util.MilkUtil;

public class SmsOutMoney3 
{
	private int smsType; 
//	private boolean flagATM = false;
//	private boolean flagHalbu = false;
//	private String halbuMonth = "0";
//	
//	private boolean FLAG = true;
	private boolean available = false;
//	
//	private boolean outmoneyFlag = false;
//	
//	//1:check 2:credit
	private int checkcreditFlag = 0;
//	
	private final int CHECK = 1;
	private final int CREDIT = 2;
//	
	private String message;
	private SmsInputData data;
//	
	private String date;
	
	public SmsOutMoney3(){};
	
	public SmsOutMoney3(SmsInputData data, String message, String date, int smsType, int checkcreditFlag)
	{
		this.data = data;
		this.message = message;
		this.date = date;
		this.smsType = smsType;
		this.checkcreditFlag = checkcreditFlag;
		
		outMoney();
	}
	
	public boolean getAvailable()
	{
		return available;
	}
	
	public SmsInputData getData()
	{
		return data;
	}
	
	public int getSmsType()
	{
		return smsType;
	}
	
	private void outMoney()
	{
		// 삼성체크, 삼성가족
		// KEB
		// 외환
		// 우리BC, 우리
		// 롯데
		// 제주
		// 광주, 광주비자
		// 올앳
		
		if ( (data.getName().indexOf("삼성체크카드") != -1) )
		{
			/*
			 * (삼성체크카드) 07/31 10:17 (주)커핀그루나루 6,400원 일시불사용 감사합니다
			 * 
			 * (삼성체크카드)
				07/27 13:57
				예스이십사(주)
				23,500원
				일시불사용
				감사합니다
			 */
			Pattern pMoney = Pattern.compile("(\\d*,*\\d*,*\\d*,*\\d)원");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("([\\d]{2}[/][\\d]{2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("\\d{2,}:\\d{2,}\\s+(.+\\s*.+)\\s+\\d*,*\\d*,*\\d*,*\\d");	
			Matcher mMemo = pMemo.matcher(message);
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(MilkUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1((mMemo.group(1)));
					data.setMemo2((mMemo.group(1)));
					data.setMemo3((mMemo.group(1)));
					data.setMemo4((mMemo.group(1)));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( (data.getName().indexOf("삼성가족카드") != -1) )
		{
			/*
				삼성가족카드승인
				01/16 18:01
				24,620원
				일시불
				세계로축산물도매
			 */
			Pattern pMoney = Pattern.compile("(\\d*,*\\d*,*\\d*,*\\d)원");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("([\\d]{2}[/][\\d]{2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("\\d{2,}:\\d{2,}\\s+\\d*,*\\d*,*\\d*,*\\d원\\s+(.+$)");	
			Matcher mMemo = pMemo.matcher(message);
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(MilkUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1((mMemo.group(1)));
					data.setMemo2((mMemo.group(1)));
					data.setMemo3((mMemo.group(1)));
					data.setMemo4((mMemo.group(1)));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if (data.getName().equalsIgnoreCase("KEB"))
		{
			
			/*
			 * [KEB]162-18**55 
				출금: 200,000   
				잔액: 7,633,343 
				01/15 13:15    
				소똥
			 */
			Pattern pName = Pattern.compile("(\\d{3,}-\\d{2,}\\*\\*\\d{2,})");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("출금:\\s+(\\d*,*\\d*,*\\d*,*\\d)");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("([\\d]{2}[/][\\d]{2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("\\d{2,}:\\d{2,}\\s+(.+$)");	
			Matcher mMemo = pMemo.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName(data.getName() + "(" + (mName.group(1)).replace("-", "") +")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(MilkUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1((mMemo.group(1)));
					data.setMemo2((mMemo.group(1)));
					data.setMemo3((mMemo.group(1)));
					data.setMemo4((mMemo.group(1)));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if (data.getName().equalsIgnoreCase("외환카드"))
		{
			
			/*
			 * [외환카드]오진석님    12,300원 G마켓WWW.GMARKET 누적액    111,300 12/06 02:28
			 * 
			 * [외환카드]임수진님     2,000원 씨제이프레시웨이 가능액     73,170 11/16 11:04
			 * 
			 * [외환카드]서정규님     14,000원 승인 해피타임         01/19 19:33
			 * 
				[외환카드]조수현님    33,800원 빠네크레아       가능액    171,158 03/31 17:33
			 * 
			 * 외환카드 홍근*님 1*0* 
				일시불      1,600원 
				GS25서강사 03/14 17:34 
				누적  1,360,145원
			 */
			Pattern pName = Pattern.compile("(\\d\\*\\d\\*)");
			Matcher mName = pName.matcher(message);
			Pattern pName2 = Pattern.compile("외환카드\\](.+)님");
			Matcher mName2 = pName2.matcher(message);
			Pattern pMoney = Pattern.compile("(\\d*,*\\d*,*\\d*,*\\d)원");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("(\\d{1,2}/\\d{1,2})");
			Matcher mDate = pDate.matcher(message);
//			Pattern pMemo = Pattern.compile("\\d*,*\\d*,*\\d*,*\\d원(.+)\\d{2}/\\d{2}");
			Pattern pMemo = Pattern.compile("\\d*,*\\d*,*\\d*,*\\d원(\\s*\\n*.+\\s*\\n*)\\d{2}/\\d{2}");	
			Matcher mMemo = pMemo.matcher(message);
			Pattern pMemo4 = Pattern.compile("\\d*,*\\d*,*\\d*,*\\d원(\\s*\\n*.+\\s*\\n*)사용가능액");	
			Matcher mMemo4 = pMemo4.matcher(message);
			Pattern pMemo2 = Pattern.compile("\\d*,*\\d*,*\\d*,*\\d원(\\s*\\n*.+\\s*\\n*)가능액");	
			Matcher mMemo2 = pMemo2.matcher(message);
			Pattern pMemo3 = Pattern.compile("\\d*,*\\d*,*\\d*,*\\d원(\\s*\\n*.+\\s*\\n*)누적");	
			Matcher mMemo3 = pMemo3.matcher(message);
			
			
			if (mName.find())
			{
				if (checkcreditFlag == CHECK)
				{
					for (int i=0; i<mName.groupCount(); i++) 
					{
						data.setName(data.getName() + "(" + (mName.group(1)) + "-체크)");
					}
				}
				else if (checkcreditFlag == CREDIT)
				{
					for (int i=0; i<mName.groupCount(); i++) 
					{
						data.setName(data.getName() + "(" + (mName.group(1)) + "-신용)");
					}
				}
			}
			else if (mName2.find())
			{
				if (checkcreditFlag == CHECK)
				{
					for (int i=0; i<mName2.groupCount(); i++) 
					{
						data.setName(data.getName() + "(" + (mName2.group(1)) + "-체크)");
					}
				}
				else if (checkcreditFlag == CREDIT)
				{
					for (int i=0; i<mName2.groupCount(); i++) 
					{
						data.setName(data.getName() + "(" + (mName2.group(1)) + "-신용)");
					}
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(MilkUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1((mMemo.group(1)).replaceAll("\\n", "").trim());
					data.setMemo2((mMemo.group(1)).replaceAll("\\n", "").trim());
					data.setMemo3((mMemo.group(1)).replaceAll("\\n", "").trim());
					data.setMemo4((mMemo.group(1)).replaceAll("\\n", "").trim());
				}
			}
			else if (mMemo4.find()) 
			{
				for (int i=0; i<mMemo4.groupCount(); i++) 
				{
					data.setMemo1((mMemo4.group(1)).replaceAll("\\n", "").trim());
					data.setMemo2((mMemo4.group(1)).replaceAll("\\n", "").trim());
					data.setMemo3((mMemo4.group(1)).replaceAll("\\n", "").trim());
					data.setMemo4((mMemo4.group(1)).replaceAll("\\n", "").trim());
				}
			}
			else if (mMemo3.find()) 
			{
				for (int i=0; i<mMemo3.groupCount(); i++) 
				{
					data.setMemo1((mMemo3.group(1)).replaceAll("\\n", "").trim());
					data.setMemo2((mMemo3.group(1)).replaceAll("\\n", "").trim());
					data.setMemo3((mMemo3.group(1)).replaceAll("\\n", "").trim());
					data.setMemo4((mMemo3.group(1)).replaceAll("\\n", "").trim());
				}
			}
			else if (mMemo2.find()) 
			{
				for (int i=0; i<mMemo2.groupCount(); i++) 
				{
					data.setMemo1((mMemo2.group(1)).replaceAll("\\n", "").trim());
					data.setMemo2((mMemo2.group(1)).replaceAll("\\n", "").trim());
					data.setMemo3((mMemo2.group(1)).replaceAll("\\n", "").trim());
					data.setMemo4((mMemo2.group(1)).replaceAll("\\n", "").trim());
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( (data.getName().indexOf("우리BC") != -1) )
		{
			/*
			 * 우리BC(6*9*)박치연님.10/13 12:19.일시불26,400원.누적금액645,180원.홈플러스(주) 익스프
			 * 
			 */
			Pattern pName = Pattern.compile("(\\(\\d\\*\\d\\*\\))");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("(\\d*,*\\d*,*\\d*,*\\d)원");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("([\\d]{2}[/][\\d]{2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("누적금액\\d*,*\\d*,*\\d*,*\\d원\\.(.+$)");	
			Matcher mMemo = pMemo.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName(data.getName() + (mName.group(1)));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(MilkUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1(mMemo.group(1));
					data.setMemo2(mMemo.group(1));
					data.setMemo3(mMemo.group(1));
					data.setMemo4(mMemo.group(1));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( data.getName().equalsIgnoreCase("우리카드") || data.getName().equalsIgnoreCase("부산BC") ) 
		{
			/*
			 * 우리카드(4*8*)이희경님.08/11 00:24.일시불.148,900원.596TOP적립예정.(주)홈앤쇼핑/무이자    
			 * 
			 * 우리카드(1*9*)황하나님.01/26 17:34.일시불.101,520원.711TOP적립예정.(주)엔터식스동탄점
			 * 
			 * 우리카드(1*4*)권동희님.01/04 21:16.일시불9,000원.누적금액733,297원.주식회사비
			 * 
			 * 
			 * [체크.승인]
				47,994원
				우리카드(4*6*)정*경님
				04/28 18:59
				지급가능액474,695원
				(주)씨제이
				
			 * [체크.승인]
				17,610원
				우리카드(2*0*)***님
				09/04 14:51
				지급가능액294,896원
				홈플러스(
				
				[체크.승인]
				16,500원
				우리카드(2*0*)***님
				10/06 15:22
				롯데쇼핑(주)잠실점
				
				[체크.승인]
				118,810원
				부산BC(2*6*)황숙현님
				08/25 12:36
				출금가능액78,464원
				(주)이마트서
				
				[매출접수]3,020원
				부산BC(0*7*)황*숙님03월09일
				교통-지하철3건
				
				[체크.승인]
				2,000원
				우리카드(5*3*)이지혜님
				01/27 16:51
				지급가능액 45,546원
				메가박스씨너
			 */
			
			Pattern pName = Pattern.compile("(\\(\\d\\*\\d\\*\\))");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("(\\d*,*\\d*,*\\d*,*\\d)원");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("([\\d]{2}[/][\\d]{2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pDate2 = Pattern.compile("님(\\d{1,2})월(\\d{1,2})일");
			Matcher mDate2 = pDate2.matcher(message);
			Pattern pMemo = Pattern.compile("\\d*,*\\d*,*\\d*,*\\d원\\.[\\d*TOP적립예정\\.*]*(.+$)");	
			Matcher mMemo = pMemo.matcher(message);
			Pattern pMemo2 = Pattern.compile("지급가능액\\s*\\d*,*\\d*,*\\d*,*\\d원\\s+(.+$)");	
			Matcher mMemo2 = pMemo2.matcher(message);
			Pattern pMemo5 = Pattern.compile("출금가능액\\s*\\d*,*\\d*,*\\d*,*\\d원\\s+(.+$)");	
			Matcher mMemo5 = pMemo5.matcher(message);
			Pattern pMemo3 = Pattern.compile("님\\s+\\d{1,2}/\\d{1,2}\\s+\\d{1,2}:\\d{1,2}\\s+(.+$)");	
			Matcher mMemo3 = pMemo3.matcher(message);
			Pattern pMemo4 = Pattern.compile("누적금액\\s*\\d*,*\\d*,*\\d*,*\\d원\\.(.+$)");	
			Matcher mMemo4 = pMemo4.matcher(message);
			Pattern pMemo6 = Pattern.compile("\\d{1,2}월\\d{1,2}일\\s+(.+$)");	
			Matcher mMemo6 = pMemo6.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName(data.getName() + (mName.group(1)));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				if (mDate2.find())
				{
					for (int i=0; i<mDate2.groupCount(); i++) 
					{
						data.setDate(date.substring(0, 4) + mDate2.group(1) + mDate2.group(2));
					}
				}
				else
				{
					data.setDate(date);
				}
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				if (mDate2.find())
				{
					for (int i=0; i<mDate2.groupCount(); i++) 
					{
						data.setDate(date.substring(0, 4) + mDate2.group(1) + mDate2.group(2));
					}
				}
				else
				{
					data.setDate(MilkUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
				}
			}
			
			if (mMemo2.find()) 
			{
				for (int i=0; i<mMemo2.groupCount(); i++) 
				{
					data.setMemo1(mMemo2.group(1));
					data.setMemo2(mMemo2.group(1));
					data.setMemo3(mMemo2.group(1));
					data.setMemo4(mMemo2.group(1));
				}
			}
			else if (mMemo5.find()) 
			{
				for (int i=0; i<mMemo5.groupCount(); i++) 
				{
					data.setMemo1(mMemo5.group(1));
					data.setMemo2(mMemo5.group(1));
					data.setMemo3(mMemo5.group(1));
					data.setMemo4(mMemo5.group(1));
				}
			}
			else if (mMemo4.find()) 
			{
				for (int i=0; i<mMemo4.groupCount(); i++) 
				{
					data.setMemo1(mMemo4.group(1));
					data.setMemo2(mMemo4.group(1));
					data.setMemo3(mMemo4.group(1));
					data.setMemo4(mMemo4.group(1));
				}
			}
			else if (mMemo3.find()) 
			{
				for (int i=0; i<mMemo3.groupCount(); i++) 
				{
					data.setMemo1(mMemo3.group(1));
					data.setMemo2(mMemo3.group(1));
					data.setMemo3(mMemo3.group(1));
					data.setMemo4(mMemo3.group(1));
				}
			}
			else if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1(mMemo.group(1));
					data.setMemo2(mMemo.group(1));
					data.setMemo3(mMemo.group(1));
					data.setMemo4(mMemo.group(1));
				}
			}
			else if (mMemo6.find()) 
			{
				for (int i=0; i<mMemo6.groupCount(); i++) 
				{
					data.setMemo1(mMemo6.group(1));
					data.setMemo2(mMemo6.group(1));
					data.setMemo3(mMemo6.group(1));
					data.setMemo4(mMemo6.group(1));
				}
			}
			
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( data.getName().indexOf("우리투자") > -1 )
		{
			/*
			 * [우리투자]김상혁님 200-01-64** 출금 04/13 [16:31] 50,000원 하나은행 정유래
			 * 
			 * [우리투자]홍길동님 200011***81 출금 02/19 [19:12] 9,600원 씨뇨르방*
			 */
			Pattern pName = Pattern.compile("님\\s*(.{1,6}-.{1,6}-.{1,6})\\s+");
			Matcher mName = pName.matcher(message);
			Pattern pName2 = Pattern.compile("님\\s*(.{1,9}\\*{1,9}.{1,9})\\s+출금");
			Matcher mName2 = pName2.matcher(message);
			Pattern pMoney = Pattern.compile("\\d{1,2}\\]\\s+(\\d*,*\\d*,*\\d*,*\\d)원\\s+");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("(\\d{1,2}/\\d{1,2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("\\d{1,2}\\]\\s+\\d*,*\\d*,*\\d*,*\\d원\\s+(.+$)");
			Matcher mMemo = pMemo.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName("우리투자" + "(" + mName.group(1).replaceAll("-", "") + ")");
				}
			}
			else if (mName2.find())
			{
				for (int i=0; i<mName2.groupCount(); i++) 
				{
					data.setName("우리투자" + "(" + mName2.group(1).replaceAll("-", "") + ")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(MilkUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1(mMemo.group(1));
					data.setMemo2(mMemo.group(1));
					data.setMemo3(mMemo.group(1));
					data.setMemo4(mMemo.group(1));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( (data.getName().indexOf("우리") != -1) )
		{
			
			/*
			 * 
			 * 우리 06/14 13:25
				*00605 
				지급 9,000원
				윤가네
				잔액 164,566원
				
				우리 06/18 16:05
				311*01 
				지급 28,000원
				주）서울문고
				잔액 125,711원
			 */
			Pattern pName = Pattern.compile("(\\*\\d{3,})");
			Matcher mName = pName.matcher(message);
			Pattern pName2 = Pattern.compile("(\\d{2,}\\*\\d{2,})");
			Matcher mName2 = pName2.matcher(message);
			Pattern pMoney = Pattern.compile("(\\d*,*\\d*,*\\d*,*\\d)원");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("([\\d]{2}[/][\\d]{2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("\\d*,*\\d*,*\\d*,*\\d원\\s+(.+)\\s+잔액");
			Matcher mMemo = pMemo.matcher(message);
			Pattern pMemo2 = Pattern.compile("\\d*,*\\d*,*\\d*,*\\d원\\s+(.+$)");
			Matcher mMemo2 = pMemo2.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName("우리" + "(" + (mName.group(1)) + ")");
				}
			}
			else if (mName2.find())
			{
				for (int i=0; i<mName2.groupCount(); i++) 
				{
					data.setName("우리" + "(" + (mName2.group(1)) + ")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(MilkUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					Pattern pMemo3 = Pattern.compile("#\\d{4,}");
					Matcher mMemo3 = pMemo3.matcher(mMemo.group(1));
					
					if (mMemo3.find())
					{
						data.setMemo1("현금 출금");
						data.setMemo2("현금 출금");
						data.setMemo3("현금 출금");
						data.setMemo4("현금 출금");
						
						smsType = SmsParser.OUT_ATM_SMS;
					}
					else
					{
						data.setMemo1((mMemo.group(1)));
						data.setMemo2((mMemo.group(1)));
						data.setMemo3((mMemo.group(1)));
						data.setMemo4((mMemo.group(1)));
					}
				}
			}
			else if (mMemo2.find()) 
			{
				for (int i=0; i<mMemo2.groupCount(); i++) 
				{
					data.setMemo1((mMemo2.group(1)));
					data.setMemo2((mMemo2.group(1)));
					data.setMemo3((mMemo2.group(1)));
					data.setMemo4((mMemo2.group(1)));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( (data.getName().indexOf("롯데카드") != -1) )
		{
			Pattern pName = Pattern.compile("(\\d\\*\\d\\*)");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("(\\d*,*\\d*,*\\d*,*\\d)원");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("([\\d]{2}[/][\\d]{2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("\\d{2,}:\\d{2,}\\s+(.+$)");	
			Matcher mMemo = pMemo.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName(data.getName() + "(" + (mName.group(1)) + ")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(MilkUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1(mMemo.group(1));
					data.setMemo2(mMemo.group(1));
					data.setMemo3(mMemo.group(1));
					data.setMemo4(mMemo.group(1));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( (data.getName().indexOf("롯데법인카드") != -1) )
		{
			Pattern pName = Pattern.compile("(\\d\\*\\d\\*)");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("(\\d*,*\\d*,*\\d*,*\\d)원");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("([\\d]{2}[/][\\d]{2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("\\d{2,}:\\d{2,}\\s+(.+$)");	
			Matcher mMemo = pMemo.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName(data.getName() + "(" + (mName.group(1)) + ")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(MilkUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1(mMemo.group(1));
					data.setMemo2(mMemo.group(1));
					data.setMemo3(mMemo.group(1));
					data.setMemo4(mMemo.group(1));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( data.getName().equalsIgnoreCase("롯데") )
		{
			Pattern pName = Pattern.compile("(\\(\\d\\*\\d\\*\\))");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("(\\d*,*\\d*,*\\d*,*\\d)원");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("([\\d]{2}[/][\\d]{2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("\\d{2,}:\\d{2,}\\s+(.+)\\s+");	
			Matcher mMemo = pMemo.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName(data.getName() + (mName.group(1)));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(MilkUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1(mMemo.group(1));
					data.setMemo2(mMemo.group(1));
					data.setMemo3(mMemo.group(1));
					data.setMemo4(mMemo.group(1));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( (data.getName().indexOf("제주카드") != -1) )
		{
			/*
			 * 제주카드 (*835) 현호영님벨로인커피 14,000원.일시불승인 01.26 18:44
			 * 
			 * 제주카드 (*662) 김은영님파리바게트제주법 2,800원.일시불승인 02.24 15:45
			 * 
			 * 제주카드(*148)
				승인 7,500원/04.20 07:25/일시불/누적 2,214,800원/문예서점
			 */
			Pattern pName = Pattern.compile("(\\(.{4}\\))");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("(\\d*,*\\d*,*\\d*,*\\d)원");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("(\\d{2}\\.\\d{2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("[^\\W+]님(.+)\\s+\\d*,*\\d*,*\\d*,*\\d원");	
			Matcher mMemo = pMemo.matcher(message);
			Pattern pMemo2 = Pattern.compile("누적\\s+\\d*,*\\d*,*\\d*,*\\d원/(.+$)");	
			Matcher mMemo2 = pMemo2.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName(data.getName() + (mName.group(1)));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(MilkUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1(mMemo.group(1));
					data.setMemo2(mMemo.group(1));
					data.setMemo3(mMemo.group(1));
					data.setMemo4(mMemo.group(1));
				}
			}
			else if (mMemo2.find()) 
			{
				for (int i=0; i<mMemo2.groupCount(); i++) 
				{
					data.setMemo1(mMemo2.group(1));
					data.setMemo2(mMemo2.group(1));
					data.setMemo3(mMemo2.group(1));
					data.setMemo4(mMemo2.group(1));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( (data.getName().indexOf("제주은행") != -1) )
		{

			/*
			 * 제주은행 07*227 13-02-26(18:23) 지급  32,620   잔액  95,269    #01046911686SKT
			 */
			Pattern pName = Pattern.compile("제주은행\\s+(.{5,8})\\s+");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("지급\\s+(\\d*,*\\d*,*\\d*,*\\d)\\s+");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("\\d{1,2}-(\\d{1,2}-\\d{1,2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("잔액\\s+-*\\d*,*\\d*,*\\d*,*\\d\\s+(.+$)");	
			Matcher mMemo = pMemo.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName(data.getName() + "(" + (mName.group(1)) + ")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("-", "")));
				}
			}
			else
			{
				data.setDate(MilkUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1(mMemo.group(1));
					data.setMemo2(mMemo.group(1));
					data.setMemo3(mMemo.group(1));
					data.setMemo4(mMemo.group(1));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( (data.getName().indexOf("올앳카드") != -1) )
		{
			Pattern pMoney = Pattern.compile("(\\d*,*\\d*,*\\d*,*\\d)원");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("(\\d{2}/\\d{2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("\\d{2}:\\d{2}\\s+(.+)\\s+\\d*,*\\d*,*\\d*,*\\d원");	
			Matcher mMemo = pMemo.matcher(message);
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(MilkUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1(mMemo.group(1));
					data.setMemo2(mMemo.group(1));
					data.setMemo3(mMemo.group(1));
					data.setMemo4(mMemo.group(1));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( (data.getName().indexOf("광주카드") != -1) || (data.getName().indexOf("광주비자") != -1))
		{
			/*
			 * 광주카드-승인.60,000원.일시불.하남노블치과.누적액:299,960원
			 * 
			 * 광주카드-승인.193,200원.일시불.주식회사쿠스.누적액:507,180원
			 * 
			 * 광주비자(체크0*0*).이**.2,000원.체크.승인.09/24.19:35.커피예담운
			 * 
			 */
			Pattern pName = Pattern.compile("(\\d\\*\\d\\*)");
			Matcher mName = pName.matcher(message);
			Pattern pName2 = Pattern.compile("광주카드");
			Matcher mName2 = pName2.matcher(message);
			Pattern pMoney = Pattern.compile("(\\d*,*\\d*,*\\d*,*\\d)원");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("([\\d]{2}[/][\\d]{2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("\\d*,*\\d*,*\\d*,*\\d원(.+\\s*.+)\\.누적액");
			Matcher mMemo = pMemo.matcher(message);
			Pattern pMemo2 = Pattern.compile("\\d{1,2}:\\d{1,2}\\.(.+$)");
			Matcher mMemo2 = pMemo2.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName(data.getName() + "(" + (mName.group(1)) + ")");
				}
			}
			else if (mName2.find())
			{
				for (int i=0; i<mName2.groupCount(); i++) 
				{
					data.setName("광주카드");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(MilkUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1((mMemo.group(1).replaceAll("\\.", "")));
					data.setMemo2((mMemo.group(1).replaceAll("\\.", "")));
					data.setMemo3((mMemo.group(1).replaceAll("\\.", "")));
					data.setMemo4((mMemo.group(1).replaceAll("\\.", "")));
				}
			}
			else if (mMemo2.find()) 
			{
				for (int i=0; i<mMemo2.groupCount(); i++) 
				{
					data.setMemo1((mMemo2.group(1)));
					data.setMemo2((mMemo2.group(1)));
					data.setMemo3((mMemo2.group(1)));
					data.setMemo4((mMemo2.group(1)));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		
		
		if (data.getName() == null || data.getName().equalsIgnoreCase(""))
		{
			SmsOutMoney4 som4 = new SmsOutMoney4(data, message, date, smsType, checkcreditFlag);
			this.data = som4.getData();
			this.smsType = som4.getSmsType();
			this.available = som4.getAvailable();
		}
		if (data.getDate() == null || data.getDate().equalsIgnoreCase(""))
		{
			SmsOutMoney4 som4 = new SmsOutMoney4(data, message, date, smsType, checkcreditFlag);
			this.data = som4.getData();
			this.smsType = som4.getSmsType();
			this.available = som4.getAvailable();
		}
		if (data.getMoney() == null || data.getMoney().equalsIgnoreCase(""))
		{
			SmsOutMoney4 som4 = new SmsOutMoney4(data, message, date, smsType, checkcreditFlag);
			this.data = som4.getData();
			this.smsType = som4.getSmsType();
			this.available = som4.getAvailable();
		}
		if ( (data.getMemo1() == null) || (data.getMemo1().equalsIgnoreCase("")) 
				&& ( (data.getMemo2() == null) || (data.getMemo2().equalsIgnoreCase("")) )
				&& ( (data.getMemo3() == null) || (data.getMemo3().equalsIgnoreCase("")) )
				&& ( (data.getMemo4() == null) || (data.getMemo4().equalsIgnoreCase("")) ) )
		{
			SmsOutMoney4 som4 = new SmsOutMoney4(data, message, date, smsType, checkcreditFlag);
			this.data = som4.getData();
			this.smsType = som4.getSmsType();
			this.available = som4.getAvailable();
		}
		if (data.getName() == null || data.getName().equalsIgnoreCase("") 
				|| data.getDate() == null || data.getDate().equalsIgnoreCase("") 
				|| data.getMoney() == null || data.getMoney().equalsIgnoreCase("")
				|| ( data.getMemo1() == null || data.getMemo1().equalsIgnoreCase("") 
				&& data.getMemo2() == null || data.getMemo2().equalsIgnoreCase("")
				&& data.getMemo3() == null || data.getMemo3().equalsIgnoreCase("")
				&& data.getMemo4() == null || data.getMemo4().equalsIgnoreCase("") ) )
		{
			this.available = false;
			return;
		}
	}
}
